library(sf)
library(mapview)Importing additional spatial data
Mined Units
The mined units can be read in directly with st_read.
mined <- st_read('https://ca.dep.state.fl.us/arcgis/rest/services/OpenData/MMP_MINEDUNITS/MapServer/0/query?outFields=*&where=1%3D1&f=geojson')Reading layer `OGRGeoJSON' from data source
`https://ca.dep.state.fl.us/arcgis/rest/services/OpenData/MMP_MINEDUNITS/MapServer/0/query?outFields=*&where=1%3D1&f=geojson'
using driver `GeoJSON'
Simple feature collection with 371 features and 10 fields
Geometry type: MULTIPOLYGON
Dimension: XY
Bounding box: xmin: -82.95369 ymin: 27.46063 xmax: -81.69582 ymax: 30.51925
Geodetic CRS: WGS 84
mapview(mined)Brownfield sites
Download the zipped kml file to a temporary directory.
# url with zipped kml
urlin <- 'https://ordsext.epa.gov/FLA/www3/acres_frs.kmz'
# download file
tmp1 <- tempfile(fileext = ".kmz")
download.file(url = urlin, destfile = tmp1, method = 'curl')Unzip the kmz file.
tmp2 <- tempdir()
unzip(tmp1, exdir = tmp2)Get the name of the kml file to read.
lyr <- unzip(tmp1, list = T)$Name
fl <- paste(c(tmp2, lyr), collapse = "\\")
fl <- gsub('\\\\', '/', fl)Read the kml file with st_read and drop Z dimension with st_zm. Here, the Tampa sites are loaded. You can view all possible locations in the kml file with st_layers.
dat <- st_read(fl, layer = 'TAMPA') %>%
st_zm()Reading layer `TAMPA' from data source `/tmp/RtmpkL00Ps/ACRES_FRS.KML' using driver `LIBKML'
Simple feature collection with 103 features and 12 fields
Geometry type: POINT
Dimension: XYZ
Bounding box: xmin: -82.51857 ymin: 27.87108 xmax: -82.3533 ymax: 28.07826
z_range: zmin: 0 zmax: 0
Geodetic CRS: WGS 84
mapview(dat)Unlink the temporary files to delete them when you are finished.
unlink(tmp1, recursive = TRUE)
unlink(fl, recursive = TRUE)Another dataset
Not sure what this one is… but process is similar except two zip files have to be unzipped.
Download zip file to temp directory and unzip to temp directory.
urlin <- 'https://static-data-screeningtool.geoplatform.gov/data-versions/1.0/data/score/downloadable/1.0-shapefile-codebook.zip'
tmp1 <- tempfile(fileext = ".zip")
download.file(url = urlin, destfile = tmp1)
tmp2 <- tempdir()
unzip(tmp1, exdir = tmp2)Unzip usa.zip file.
zip1 <- list.files(tmp2, 'usa\\.zip', full.names = T)
unzip(zip1, exdir = tmp2)Get file path for usa.shp, import with sf.
fl <- list.files(tmp2, '\\.shp', full.names = T)
dat <- st_read(fl)Reading layer `usa' from data source `/tmp/RtmpkL00Ps/usa.shp' using driver `ESRI Shapefile'
Simple feature collection with 74134 features and 123 fields (with 367 geometries empty)
Geometry type: MULTIPOLYGON
Dimension: XY
Bounding box: xmin: -179.2311 ymin: -14.60181 xmax: 179.8597 ymax: 71.44106
Geodetic CRS: WGS 84
Clip to Tampa Bay watershed boundaries. CRS is the same, so no need to transform.
load(file = 'data/tbshed.RData')
dattb2 <- dat %>%
st_intersection(tbshed)
save(dattb2, file = 'data/dattb2.RData')View the data.
mapview(dattb2)Remove temporary files.
unlink(tmp1, recursive = TRUE)
unlink(zip1)
fls <- list.files(tmp2, gsub('\\.shp$', '', basename(fl)), full.names = T)
file.remove(fls)[1] TRUE TRUE TRUE TRUE TRUE